//
//  PendApprovalInfoBasicViewController.m
//  ZJControlsClass
//
//  Created by apple on 2024/11/1.
//

#import "PendApprovalInfoBasicViewController.h"
#import "PendApprovalInfoBasicTableViewCell.h"
#import "ZJPublicUploadPhotoTableViewCell.h"
#import "ZJPublicSPinfoImageTableViewCell.h"
#import "PendApprovalAreaLayoutTableViewCell.h"
#import "PendApprovalNewAddTableViewCell.h"
#import "PendApprovalAddNewApprovalTableViewCell.h"
#import "PendApprovalHaveFormTableViewCell.h"
#import "HomeUploadFileTableViewCell.h"

@interface PendApprovalInfoBasicViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * dataSource;
@property (nonatomic,strong) NSMutableArray * temp;

//@property (nonatomic,strong) NSMutableDictionary * ApprovalDic;// 审核
@property (nonatomic,strong) NSMutableArray * ApprovalArr;// 审核
@property (nonatomic,strong) NSMutableArray * ApprovalDataSource; // 审核含表单
@property (nonatomic,strong) NSMutableDictionary * paymentDic;// 付款
@property (nonatomic,strong) NSMutableDictionary * trainDic; // 培训
@property (nonatomic,strong) NSMutableDictionary * examDic; // 考试

@end

@implementation PendApprovalInfoBasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setUpUI];
    
    
}

-(void)setUpUI{
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.right.equalTo(self.view);
    }];
    
    
    
    
}


-(void)setModel:(ZJPendApprovallInfoModel *)model{
    _model = model;
    // 解析formItems

    if (!model.processTemplates.formItems){
        return;
    }
    
    
    
    NSData *jsonData = [model.processTemplates.formItems dataUsingEncoding:NSUTF8StringEncoding];
    
    NSError *error;
    NSMutableArray * array = @[].mutableCopy;
    array = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
    
    NSLog(@"=====-----444444%@",array);
    if (error) {
        NSLog(@"JSON解析出错：%@", error);
        [LUtilityTools showAlertWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"JSON解析formItems出错：%@", error] buttonAction:^{
            
        }];
        
        return;
    }

    NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithDictionary:model.formData];
    
    // 遍历字典
    [self.temp addObjectsFromArray:array];

    for (int i = 0; i < self.temp.count; i ++) {
        
        for (NSString * sss in dic) {
        
            if ([sss containsString:self.temp[i][@"id"]]){
                NSMutableDictionary * ddd = [NSMutableDictionary dictionaryWithDictionary:self.temp[i]];
                [ddd setValue:[dic valueForKey:sss] forKey:@"temp"];
                NSLog(@"ssssss == %@",ddd);
                [self.dataSource addObject:ddd];
                
            }
        }
        
    }
    self.ApprovalArr = [NSMutableArray array];
    [self.model.detailVOList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj[@"nodeType"] isEqualToString:@"APPROVAL"]){ // 审核
            if (![obj[@"result"] isKindOfClass:[NSNull class]])
                [self.ApprovalArr addObject:obj];
        }
        
        if ([obj[@"nodeType"] isEqualToString:@"FORM"]){ // 审核 含表单
             // 填充表单内容在最外层的formdata
            NSData *FORMjsonData = [obj[@"formItems"] dataUsingEncoding:NSUTF8StringEncoding];
            
            NSError *error;
            NSMutableArray * FORMarray = @[].mutableCopy;
            FORMarray = [NSJSONSerialization JSONObjectWithData:FORMjsonData options:kNilOptions error:&error];
            
            NSLog(@"=====-----555555%@",FORMarray);
            if (error) {
                NSLog(@"JSON解析出错：%@", error);
                [LUtilityTools showAlertWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"JSON解析formItems出错：%@", error] buttonAction:^{
                }];
                return;
            }
            NSMutableArray * tempArr = @[].mutableCopy;
            if (![obj[@"formData"] isKindOfClass:[NSNull class]] && obj[@"formData"] != nil){
                NSMutableDictionary * FormDic = [NSMutableDictionary dictionaryWithDictionary:obj[@"formData"]];
                for (int j = 0; j < FORMarray.count; j ++) {
                
                    for (NSString * str in FormDic) {
                        
                        if ([str containsString:FORMarray[j][@"id"]]){
                            NSMutableDictionary * d = [NSMutableDictionary dictionaryWithDictionary:FORMarray[j]];
                            [d setValue:[FormDic valueForKey:str] forKey:@"temp"];
                            [tempArr addObject:d];
                        }
                        
                    }
                    
                }
            }
            
            // 将需要的数据 添加到ApprovalDataSource中去
            // &前是左边展示的   &后是value
//            [self.ApprovalDataSource addObject:@{@"leftName":[NSString stringWithFormat:@"审批人&%@/%@",self.ApprovalDic[@"user"][@"name"],self.ApprovalDic[@"user"][@"orgName"]]}];
//            [self.ApprovalDataSource addObject:@{@"leftName":[NSString stringWithFormat:@"审批时间&%@",self.ApprovalDic[@"endTime"]]}];
//            [self.ApprovalDataSource addObject:@{@"leftName":[NSString stringWithFormat:@"审批结果&%@",self.ApprovalDic[@"result"]]}];
//            [self.ApprovalDataSource addObject:@{@"leftName":[NSString stringWithFormat:@"审批意见&%@",self.ApprovalDic[@"option"]]}];
            
            [tempArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [self.ApprovalDataSource addObject:obj];
            }];
            
        }
        
        
        if ([obj[@"nodeType"] isEqualToString:@"PAYMENT"]){
//            if ((![obj[@"result"] isKindOfClass:[NSNull class]] && obj[@"result"] != nil) && (![obj[@"formdata"] isKindOfClass:[NSNull class]] && obj[@"formdata"] != nil)){
            if (![obj[@"result"] isKindOfClass:[NSNull class]] && ![obj[@"formdata"] isKindOfClass:[NSNull class]]){
                self.paymentDic = [NSMutableDictionary dictionaryWithDictionary:obj];
            }
        }
        if ([obj[@"nodeType"] isEqualToString:@"TRAIN"]){
            if (![obj[@"result"] isKindOfClass:[NSNull class]]  && ![obj[@"formdata"] isKindOfClass:[NSNull class]]){
                self.trainDic = [NSMutableDictionary dictionaryWithDictionary:obj];
            }
        }
        if ([obj[@"nodeType"] isEqualToString:@"EXAM"]){
            if (![obj[@"result"] isKindOfClass:[NSNull class]] && ![obj[@"formdata"] isKindOfClass:[NSNull class]] ){
                self.examDic = [NSMutableDictionary dictionaryWithDictionary:obj];
            }
        }
    }];
    
    
    
    [self.tableView reloadData];

    
}



#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0){
        return self.dataSource.count;
    }else if (section == 1){ // 审核含表单
        return self.ApprovalDataSource.count > 0 ? self.ApprovalDataSource.count : 0;
    }else if (section == 2){ // 审核
        return self.ApprovalArr.count;
    }else if (section == 3){ // 付款
        if (self.paymentDic){
            return 1;
        }
    }else if (section == 4){ // 培训
        if (self.trainDic){
            return 1;
        }
    }else if (section == 5){ // 考试
        if (self.examDic){
            return 1;
        }
    }else{
        return 0;
    }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"personal_card_face_photo"]){ // 身份证
//
//
//        ZJPublicUploadPhotoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJPublicUploadPhotoTableViewCell"];
//        if (!cell) {
//            cell = [[ZJPublicUploadPhotoTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJPublicUploadPhotoTableViewCell"];
//        }
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.addImg.hidden = YES;
//        cell.uploadLabel.hidden = YES;
//        cell.titleLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[indexPath.row][@"props"][@"title"]];
//
//        return cell;
//
//    }else
    
    if (indexPath.section == 0){
        if ([self.dataSource[indexPath.row][@"valueType"] isEqualToString:@"Image"] || ([self.dataSource[indexPath.row][@"valueType"] isEqualToString:@"Upload"] && ![self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_file"] )){
            ZJPublicSPinfoImageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJPublicSPinfoImageTableViewCell"];
            //        if (!cell){
            cell = [[ZJPublicSPinfoImageTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJPublicSPinfoImageTableViewCell"];
            //        }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.paramer = self.dataSource[indexPath.row];
            
            return cell;
            
        }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_apply_pass_region"] || [self.dataSource[indexPath.row][@"name"] isEqualToString:@"tool_pass_region"]){ // 通行区域
            
            PendApprovalAreaLayoutTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PendApprovalAreaLayoutTableViewCell"];
            //            if (!cell){
            cell = [[PendApprovalAreaLayoutTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"PendApprovalAreaLayoutTableViewCell"];
            //            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.paramer = self.dataSource[indexPath.row];
            
            return cell;
            
            
        }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"tool_table"]){ // 物品基本信息
            
            
            
            
            
        }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_file"]){ // 文件上传
            
            HomeUploadFileTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeUploadFileTableViewCell"];
            if (!cell) {
                cell = [[HomeUploadFileTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"HomeUploadFileTableViewCell"];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.paramer = self.dataSource[indexPath.row];

            return cell;
            
            
            
        }else{
            PendApprovalInfoBasicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PendApprovalInfoBasicTableViewCell"];
            //        if (!cell) {
            cell = [[PendApprovalInfoBasicTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"PendApprovalInfoBasicTableViewCell"];
            //        }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.titleLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[indexPath.row][@"props"][@"title"]];
            if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_department_id"]){ // 部门
                
                NSDictionary * dic = [SStringUtils dataUsingEncoding:self.dataSource[indexPath.row][@"temp"]];
                cell.msgLabel.text = [NSString stringWithFormat:@"%@",dic[@"name"]];
                
            }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_passport_outdate"] || [self.dataSource[indexPath.row][@"name"] isEqualToString:@"tool_time"]){ // 通行有效期 tool_time
                NSArray * arr = self.dataSource[indexPath.row][@"temp"];
                if (arr.count > 0){
                    NSString * timeStr = [arr componentsJoinedByString:@"至"];
                    cell.msgLabel.text = timeStr;
                    cell.msgLabel.adjustsFontSizeToFitWidth = YES;
                }
                
            }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_user_id"] ) { // 员工
                NSArray * arr = [SStringUtils dataUsingEncodingByArr:self.dataSource[indexPath.row][@"temp"]];
                NSMutableArray * temp = @[].mutableCopy;
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    [temp addObject:obj[@"name"]];
                }];
                cell.msgLabel.text = [temp componentsJoinedByString:@"/"];
            }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"personal_leading_people"]){  // 引领人
                
                NSArray * arr = [SStringUtils dataUsingEncodingByArr:self.dataSource[indexPath.row][@"temp"]];
                NSMutableArray * temp = @[].mutableCopy;
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    [temp addObject:obj[@"name"]];
                }];
                cell.msgLabel.text = [temp componentsJoinedByString:@"/"];
                
            }else{
                cell.msgLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[indexPath.row][@"temp"]];
            }
            
            return cell;
        }
        
    }else if (indexPath.section == 1){
        
        id model = self.ApprovalDataSource[indexPath.row];
            if ([model[@"valueType"] isEqualToString:@"Image"] || ([model[@"valueType"] isEqualToString:@"Upload"] && ![model[@"name"] isEqualToString:@"common_file"] )){
                ZJPublicSPinfoImageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJPublicSPinfoImageTableViewCell"];
                //        if (!cell){
                cell = [[ZJPublicSPinfoImageTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJPublicSPinfoImageTableViewCell"];
                //        }
                
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.paramer = model;
                
                return cell;
                
            }else if ([model[@"name"] isEqualToString:@"common_apply_pass_region"] || [model[@"name"] isEqualToString:@"tool_pass_region"]){ // 通行区域
                
                PendApprovalAreaLayoutTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PendApprovalAreaLayoutTableViewCell"];
                //            if (!cell){
                cell = [[PendApprovalAreaLayoutTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"PendApprovalAreaLayoutTableViewCell"];
                //            }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.paramer = model;
                
                return cell;
                
                
            }else if ([model[@"name"] isEqualToString:@"tool_table"]){ // 物品基本信息
                
                
                
                
                
            }else if ([model[@"name"] isEqualToString:@"common_file"]){ // 文件上传
                
                HomeUploadFileTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeUploadFileTableViewCell"];
                if (!cell) {
                    cell = [[HomeUploadFileTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"HomeUploadFileTableViewCell"];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                cell.paramer = model;
    //            cell.model = model;

                return cell;
                
                
                
            }else{
                PendApprovalInfoBasicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PendApprovalInfoBasicTableViewCell"];
                //        if (!cell) {
                cell = [[PendApprovalInfoBasicTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"PendApprovalInfoBasicTableViewCell"];
                //        }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.titleLabel.text = [NSString stringWithFormat:@"%@",model[@"props"][@"title"]];
                if ([model[@"name"] isEqualToString:@"common_department_id"]){ // 部门
                    
                    NSDictionary * dic = [SStringUtils dataUsingEncoding:model[@"temp"]];
                    cell.msgLabel.text = [NSString stringWithFormat:@"%@",dic[@"name"]];
                    
                }else if ([model[@"name"] isEqualToString:@"common_passport_outdate"] || [model[@"name"] isEqualToString:@"tool_time"]){ // 通行有效期 tool_time
                    NSArray * arr = model[@"temp"];
                    if (arr.count > 0){
                        NSString * timeStr = [arr componentsJoinedByString:@"至"];
                        cell.msgLabel.text = timeStr;
                        cell.msgLabel.adjustsFontSizeToFitWidth = YES;
                    }
                    
                }else if ([model[@"name"] isEqualToString:@"common_user_id"] ) { // 员工
                    NSArray * arr = [SStringUtils dataUsingEncodingByArr:model[@"temp"]];
                    NSMutableArray * temp = @[].mutableCopy;
                    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        [temp addObject:obj[@"name"]];
                    }];
                    cell.msgLabel.text = [temp componentsJoinedByString:@"/"];
                }else if ([model[@"name"] isEqualToString:@"personal_leading_people"]){  // 引领人
                    
                    NSArray * arr = [SStringUtils dataUsingEncodingByArr:model[@"temp"]];
                    NSMutableArray * temp = @[].mutableCopy;
                    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                        [temp addObject:obj[@"name"]];
                    }];
                    cell.msgLabel.text = [temp componentsJoinedByString:@"/"];
                    
                }else{
                    cell.msgLabel.text = [NSString stringWithFormat:@"%@",model[@"temp"]];
                }
                
                return cell;
            }
            
    }else if (indexPath.section == 2) {
     
        PendApprovalAddNewApprovalTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PendApprovalAddNewApprovalTableViewCell"];
        if (!cell){
            cell = [[PendApprovalAddNewApprovalTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"PendApprovalAddNewApprovalTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell approvalParamer:self.ApprovalArr[indexPath.row]];
        return cell;
        
    }else {
        
        PendApprovalNewAddTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PendApprovalNewAddTableViewCell"];
        if (!cell){
            cell = [[PendApprovalNewAddTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"PendApprovalNewAddTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        if (indexPath.section == 3){
            
            [cell changeCellValueWithType:1 Paramer:self.paymentDic];
            
        }else if (indexPath.section == 4){
            
            [cell changeCellValueWithType:2 Paramer:self.trainDic];
            
        }else if (indexPath.section == 5){
            
            [cell changeCellValueWithType:3 Paramer:self.examDic];
        }
        
        return cell;
    }
    
    
    return [UITableViewCell new];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0){
        id paramer = self.dataSource[indexPath.row];
        
        if ([paramer[@"name"] isEqualToString:@"common_apply_pass_region"] || [paramer[@"name"] isEqualToString:@"tool_pass_region"]){
            // 高度自适应
            return [self.tableView cellHeightForIndexPath:indexPath model:paramer keyPath:@"paramer" cellClass:[PendApprovalAreaLayoutTableViewCell class] contentViewWidth:SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(30)];
        }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_file"]){
            return ALIGN_HEIGHT_PT(100);
        }else{
            return ALIGN_HEIGHT_PT(60);
        }
    }else if (indexPath.section  == 1){
        if (self.ApprovalDataSource.count != 0) {
//            return ALIGN_HEIGHT_PT(45);
            id paramer = self.ApprovalDataSource[indexPath.row];
            
            if ([paramer[@"name"] isEqualToString:@"common_apply_pass_region"] || [paramer[@"name"] isEqualToString:@"tool_pass_region"]){
                // 高度自适应
                return [self.tableView cellHeightForIndexPath:indexPath model:paramer keyPath:@"paramer" cellClass:[PendApprovalAreaLayoutTableViewCell class] contentViewWidth:SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(30)];
            }else if ([self.dataSource[indexPath.row][@"name"] isEqualToString:@"common_file"]){
                return ALIGN_HEIGHT_PT(100);
            }else{
                return ALIGN_HEIGHT_PT(60);
            }
            
        }else{
            return 0;
        }
        
        
    }else if (indexPath.section == 2){
        if (self.ApprovalArr.count != 0) {
            // 计算审批意见文本高度
            
            NSDictionary * height = self.ApprovalArr[indexPath.row];
            
            NSString *option = ![height[@"option"] isKindOfClass:[NSNull class]] ?
            height[@"option"][@"comments"] : @"";
            CGFloat textHeight = [option boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 60, MAXFLOAT)
                                                    options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                                 attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}
                                                    context:nil].size.height;
            textHeight = MAX(textHeight, ALIGN_HEIGHT_PT(45));
            // 基础高度(3个固定行) + 审批意见文本高度
            return ALIGN_HEIGHT_PT(45 * 4) + textHeight + ALIGN_HEIGHT_PT(1);
        }
    }else if (indexPath.section == 3){
        if (self.paymentDic){
            return ALIGN_HEIGHT_PT(180);
        }
    }else if (indexPath.section == 4){
        if (self.trainDic){
            return ALIGN_HEIGHT_PT(180);
        }
    }else if (indexPath.section == 5){
        if (self.examDic){
            return ALIGN_HEIGHT_PT(180);
        }
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView * HeadView = [UIView new];
    HeadView.backgroundColor = [UIColor whiteColor];
    
    if (section == 1){
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, ALIGN_HEIGHT_PT(45))];
        label.font = [UIFont systemFontOfSize:16 weight:0.3];
        label.text = @"审核(含表单)";
        label.textColor = [UIColor blackColor];
        if (self.ApprovalDataSource.count != 0) {
            [HeadView addSubview:label];
        }
    }
    
    return HeadView;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view = [UIView new];
    return view;
}



-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1){
        if (self.ApprovalDataSource.count != 0) {
            return ALIGN_HEIGHT_PT(45);
        }
    }
    return 0.0001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}



#pragma mark -- 懒加载
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

-(NSMutableArray *)dataSource{
    if (!_dataSource){
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

-(NSMutableArray *)ApprovalDataSource{
    if (!_ApprovalDataSource){
        _ApprovalDataSource = [NSMutableArray array];
    }
    return _ApprovalDataSource;
}


-(NSMutableArray *)temp{
    if(!_temp){
        _temp = [NSMutableArray array];
    }
    return _temp;
}



@end
